/*
 * Copyright 2016-2021 Pnoker. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xj.business.simulate.service.job;
import com.xj.business.simulate.service.ModelScheduleService;
import com.xj.business.simulate.service.SimulateService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 自定义调度任务
 *
 * @author pnoker
 */
@Slf4j
@Component
public class SumlateScheduleJob extends QuartzJobBean {

    @Resource
    SimulateService simulateService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //获取参数
        JobDataMap data = jobExecutionContext.getJobDetail().getJobDataMap();
        String level = data.getString("level");
        Long id = data.getLong("id");
        if(level.equals("tenant")){
            simulateService.tenantSimulate(id);
        }else if(level.equals("driver")){
            simulateService.driverSimulate(id);
        }else if(level.equals("device")){
            simulateService.deviceSimulate(id);
        }else{
            System.out.println("发送模拟源命令出错：错误level为"+level);
        }
    }
}